<?php

require_once(PATH_tslib.'class.tslib_pibase.php');
require_once(PATH_t3lib."class.t3lib_basicfilefunc.php");
require_once(t3lib_extMgm::extPath('rtehtmlarea').'pi2/class.tx_rtehtmlarea_pi2.php');
require_once(t3lib_extMgm::extPath("mt_prize")."pi1/class.tx_mtprize_pi1.php");

/**
 * Plugin 'FE news adder' for the 'mt_fenews' extension.
 *
 * @author	Grzegorz Bańka <grzegorz.banka@gmail.com>
 * @package	TYPO3
 * @subpackage	tx_mtfenews
 */
class tx_mtfenews_pi1 extends tslib_pibase {
	var $prefixId      = 'tx_mtfenews_pi1';		// Same as class name
	var $scriptRelPath = 'pi1/class.tx_mtfenews_pi1.php';	// Path to this script relative to the extension dir.
	var $extKey        = 'mt_fenews';	// The extension key.
	var $pi_checkCHash = true;
	
	var $RTEObj;
	var $docLarge = 0;
	var $RTEcounter = 0;
	var $formName;
	var $additionalJS_initial = '';// Initial JavaScript to be printed before the form (should be in head, but cannot due to IE6 timing bug)
	var $additionalJS_pre = array();// Additional JavaScript to be printed before the form (works in Mozilla/Firefox when included in head, but not in IE6)
	var $additionalJS_post = array();// Additional JavaScript to be printed after the form
	var $additionalJS_submit = array();// Additional JavaScript to be executed on submit
	var $PA = array(
	'itemFormElName' =>  '',
	'itemFormElValue' => '',
	);
	var $specConf = array(
	'rte_transform' => array(
	'parameters' => array('mode' => 'ts_css')
	)
	);
	var $thisConfig = array();
	var $RTEtypeVal = 'text';
	var $thePidValue;
	
	/**
	 * The main method of the PlugIn
	 *
	 * @param	string		$content: The PlugIn content
	 * @param	array		$conf: The PlugIn configuration
	 * @return	The content that is displayed on the website
	 */
	 
	function main($content, $conf) {
		$this->conf = $conf;
		$this->pi_setPiVarDefaults();
		$this->pi_loadLL();
		$this->pi_initPIflexForm();		// Init FlexForm configuration for plugin
		$this->captch_error=0;

		//print_r($_POST);
		
		$redirect_pages=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'redirect_pages', 'sDEF'));
		$is_moderate=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'is_moderate', 'sDEF'));
		$news_pid=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'news_pid', 'sDEF'));
		$template_file=$this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'template_file', 'sDEF');
		if($template_file!='' && $template_file!='EXT:mt_fenews/pi1/template.html') $this->conf['templateFile']=$template_file;

		$this->setting['redirect_pages']=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'redirect_pages', 'sDEF'));
		$this->setting['is_moderate']=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'is_moderate', 'sDEF'));
		$this->setting['news_pid']=$this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'news_pid', 'sDEF');
		if($this->setting['news_pid']!='') $this->setting['news_pid']=intval($this->setting['news_pid']);
		$this->setting['ttnews_parameter']=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'ttnews_parameter', 'advanced'));
		$this->setting['error_redirect_pages']=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'error_redirect_pages', 'advanced'));
		$this->setting['add_category']=$this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'add_category', 'advanced');
		if($this->setting['add_category']!='' && stristr($this->setting['add_category'],',')) $this->setting['add_category']=explode(',',$this->setting['add_category']);
		elseif($this->setting['add_category']!='') $this->setting['add_category']=array($this->setting['add_category']);
		$this->setting['tt_news_returnUrl']=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'tt_news_returnUrl', 'advanced'));
		$this->setting['without_category']=$this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'without_category', 'advanced');
		if($this->setting['without_category']!='' && stristr($this->setting['without_category'],',')) $this->setting['without_category']=explode(',',$this->setting['without_category']);
		else $this->setting['without_category']=array($this->setting['without_category']);
		
		$this->setting['only_show_category']=$this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'only_show_category', 'advanced');
		if($this->setting['only_show_category']!='' && stristr($this->setting['only_show_category'],',')) $this->setting['only_show_category']=explode(',',$this->setting['only_show_category']);
		else $this->setting['only_show_category']=array($this->setting['only_show_category']);
		if(isset($_GET['tx_ttnews']['cat']) && in_array(intval($_GET['tx_ttnews']['cat']),$this->setting['only_show_category'])) $this->setting['only_show_category']=array(intval($_GET['tx_ttnews']['cat']));
		else if(isset($_GET['tx_ttnews']['cat']) && $this->conf['use_all_category']==0) 
		{
			$array_param = array(
			//'useCacheHash' =>1,
			'parameter' => $this->setting['error_redirect_pages'].' _self',
			'returnLast'=>'url'
			);
			
			header('Location: '.$this->cObj->typolink('',$array_param));
			exit;
		}else
		{
			$this->setting['only_show_category']=array(intval($_GET['tx_ttnews']['cat']));
		}
		
		
		$this->setting['workSpace']=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'workSpace', 'advanced'));
		$this->setting['image_count']=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'image_count', 'advanced'));
		$this->setting['ttnews_edit']=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'ttnews_edit', 'advanced'));
		
		$this->setting['for_fe_login']=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'for_fe_login', 'sDEF'));
		$what_to_display=$this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'what_to_display', 'sDEF');

		$all=array(
		'captch',
		'news_title',
		'category',
		'author',
		'email',
		'short',
		'body',
		'keyword',
		'image',
		'desc_image',
		'alt_image',
		'title_image',
		
		'next_image',
		'image_next',
		'desc_image_next',
		'alt_image_next',
		'title_image_next',
		
		'youtube',

		'links',
		'newsfile',
		);
		$this->name_marker=$all;
		
		$this->db_all = array (
		'news_title'		=> 'title',
		'category'			=> 'category',
		'author'			=> 'author', 
		'email'				=> 'author_email',
		'short'				=> 'short',
		'body'				=> 'bodytext',
		'keyword'			=> 'keywords',
		
		'image'				=> 'image',
		'desc_image'		=> 'imagecaption',
		'alt_image'			=> 'imagealttext',
		'title_image'  		=> 'imagetitletext',

		'image_next'		=> 'image',
		'desc_image_next'	=> 'imagecaption',
		'alt_image_next'	=> 'imagealttext',
		'title_image_next'  => 'imagetitletext',

		'youtube'			=>	'tx_ttnewsyoutube_youtubevideo',

		'links'				=> 'links',
		'newsfile'			=> 'news_files'
		);
		
		$this->all_next_image=array(
		'image_next',
		'desc_image_next',
		'alt_image_next',
		'title_image_next'
		);
		$this->all_no_empty=array(
		'desc_image',
		'alt_image',
		'title_image',
		'image_next',
		'desc_image_next',
		'alt_image_next',
		'title_image_next'
		);
		
		$show['captch']=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'captch', 'show_input'));
		$show['news_title']=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'news_title', 'show_input'));
		$show['category']=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'category', 'show_input'));
		$show['author']=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'author', 'show_input'));
		$show['email']=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'email', 'show_input'));
		$show['short']=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'short', 'show_input'));
		$show['body']=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'body', 'show_input'));
		$show['keyword']=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'keyword', 'show_input'));
		$show['image']=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'image', 'show_input'));
		$show['desc_image']=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'desc_image', 'show_input'));
		$show['alt_image']=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'alt_image', 'show_input'));
		$show['title_image']=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'title_image', 'show_input'));
		$show['youtube']=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'youtube', 'show_input'));
				
		$show['links']=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'links', 'show_input'));
		$show['newsfile']=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'newsfile', 'show_input'));

		$request['captch']=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'captch', 'request_input'));
		$request['news_title']=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'news_title', 'request_input'));
		$request['category']=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'category', 'request_input'));
		$request['author']=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'author', 'request_input'));
		$request['email']=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'email', 'request_input'));
		$request['short']=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'short', 'request_input'));
		$request['body']=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'body', 'request_input'));
		$request['keyword']=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'keyword', 'request_input'));
		$request['image']=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'image', 'request_input'));
		$request['desc_image']=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'desc_image', 'request_input'));
		$request['alt_image']=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'alt_image', 'request_input'));
		$request['title_image']=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'title_image', 'request_input'));
		$request['youtube']=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'youtube', 'request_input'));		
		
		$request['links']=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'links', 'request_input'));
		$request['newsfile']=intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'newsfile', 'request_input'));

		if($this->setting['image_count']>0) 
		{
			for($i=0; $i<$this->setting['image_count']; $i++)
			{
				//
				if(intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'image_next', 'show_input'))==1)
				{
					$name='image_next_'.$i;
					$show[$name]=1;
					$all[]=$name;
				}
				if(intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'image_next', 'request_input'))==1)
				{
					$name='image_next_'.$i;
					$request[$name]=1;
				}
				//
				if(intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'desc_image_next', 'show_input'))==1)
				{
					$name='desc_image_next_'.$i;
					$show[$name]=1;
					$all[]=$name;
				}
				if(intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'desc_image_next', 'request_input'))==1)
				{
					$name='desc_image_next_'.$i;
					$request[$name]=1;
				}
				//
				if(intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'alt_image_next', 'show_input'))==1)
				{
					$name='alt_image_next_'.$i;
					$show[$name]=1;
					$all[]=$name;
				}
				if(intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'alt_image_next', 'request_input'))==1)
				{
					$name='alt_image_next_'.$i;
					$request[$name]=1;
				}
				//
				if(intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'title_image_next', 'show_input'))==1)
				{
					$name='title_image_next_'.$i;
					$show[$name]=1;
					$all[]=$name;
				}
				if(intval($this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'title_image_next', 'request_input'))==1)
				{
					$name='title_image_next_'.$i;
					$request[$name]=1;
				}
			}
		}
		$work_for_fe=0;
		if($this->setting['for_fe_login']==1 && $GLOBALS["TSFE"]->fe_user->user['uid']=='') $work_for_fe=1;
		if($work_for_fe==0)
		{
			if($what_to_display=='EDIT' && $this->piVars['edit']!='' || $what_to_display=='ADD')
			{
				if(!isset($this->piVars['submit_news'])) $content=$this->form($show,$request,$all,$what_to_display);
				else 
				{
						$content=$this->form($show,$request,$all,$what_to_display);
						if($this->error=='') $content=$this->inset($what_to_display);					
				}
			}
		}
		return $this->pi_wrapInBaseClass($content);
	}
	function inset($what_to_display)
	{
		$return='';
		if($this->setting['news_pid']!='') $this->query['pid']=$this->setting['news_pid'];
		else $this->query['pid']=intval($this->conf['newsPid']);
		$this->query['tstamp']=time();
		$this->query['crdate']=time();
		$this->query['datetime']=time();
		$this->query['deleted']=0;
		$this->query['hidden']=$this->setting['is_moderate'];
		$this->query['tx_mtfenews_user']=intval($GLOBALS["TSFE"]->fe_user->user['uid']);
		if(isset($_GET['tx_ttnews']['cat'])) $this->setting['add_category']=array_merge(array($_GET['tx_ttnews']['cat']),$this->setting['add_category']);

		if($this->setting['add_category'][0]!='') $this->setting['add_category'] = array_merge($this->setting['add_category'],$this->query['category']);
		elseif($this->query['category']!='') $this->setting['add_category']=$this->query['category'];
		$this->query['category']=count($this->setting['add_category']);
		//$this->query['tx_mtfenews_page_pid']=$this->setting['add_category'];
		if($this->query['author']=='') $this->query['author']=$GLOBALS["TSFE"]->fe_user->user['username'];
		$this->query['short']=str_replace('\r\n',"\r\n",$this->query['short']);

		if(strlen(str_replace("\n",'',$this->query['imagecaption']))<3) $this->query['imagecaption']='';
		if(strlen(str_replace("\n",'',$this->query['imagealttext']))<3) $this->query['imagealttext']='';
		if(strlen(str_replace("\n",'',$this->query['imagetitletext']))<3) $this->query['imagetitletext']='';

		//if(strlen($this->query['imagecaption']
		//imagealttext 	imagetitletext
		
		if($what_to_display=='EDIT')
		{
			
			unset($this->query['crdate']);
			$query = $GLOBALS['TYPO3_DB']->UPDATEquery('tt_news', 'uid="'.$this->news_uid.'"', $this->query);		
			$res = $GLOBALS['TYPO3_DB']->sql(TYPO3_db, $query);	
			$uid_news=$this->news_uid;			
		}
		else
		{
			
			$GLOBALS['TYPO3_DB']->exec_INSERTquery(
					'tt_news',
					$this->query
			);
			$uid_news=$GLOBALS['TYPO3_DB']->sql_insert_id();

			if($this->conf['add_prize']==1)
			{
			
				$count=$this->conf['mt_prize.']['points_count'];
				$feuser=$GLOBALS["TSFE"]->fe_user->user['uid'];
				$desc=$this->conf['mt_prize.']['description'];
				$plus=$this->conf['mt_prize.']['plus'];
				$db_table= $this->conf['mt_prize.']['db_table'];
				$db_table_uid= $uid_news;
				$pid= $this->conf['mt_prize.']['pid'];
		
				$mt_prize= new tx_mtprize_pi1;
				$mt_prize->add_points($count,$feuser,$desc,$plus,$db_table,$db_table_uid,$pid);
				//print_r('aaaaaaa');exit;

			}
		}
		
		$nr=1;
		
			/*
			$query = $GLOBALS['TYPO3_DB']->DELETEquery('tt_news', 'uid="'.$this->news_uid.'"', $this->query);		
			$res = $GLOBALS['TYPO3_DB']->sql(TYPO3_db, $query);	
			*/
		$this->setting['add_category']=array_unique($this->setting['add_category']);
		for($i=0; $i<$this->query['category']; $i++)
		{
			if(!in_array($this->setting['add_category'][$i],$this->category) && !in_array($this->setting['add_category'][$i],$this->setting['without_category']))
			{
				$insertArray['uid_local'] = $uid_news;
				$insertArray['uid_foreign']	= $this->setting['add_category'][$i];
				$insertArray['sorting'] = $nr;
				
				$GLOBALS['TYPO3_DB']->exec_INSERTquery(
					'tt_news_cat_mm',
					$insertArray   			
				);
				$nr++;
			}
		}
		for($i=0; $i<count($this->category); $i++)
		{
			if(!in_array($this->category[$i],$this->setting['add_category'])) 
			{
				$query = $GLOBALS['TYPO3_DB']->DELETEquery('tt_news_cat_mm', 'uid_local="'.$uid_news.'" AND uid_foreign="'.$this->category[$i].'"', $this->query);		
				$res = $GLOBALS['TYPO3_DB']->sql(TYPO3_db, $query);	
			}
		}
		
		if($this->setting['workSpace']!=0) 
		{
			$this->query['pid']='-1';
			$this->query['cruser_id']=1;
			$this->query['t3ver_oid']=$uid_news; 	
			$this->query['hidden']=0;
			$this->query['t3ver_id']=1;
			$this->query['t3ver_wsid']=$this->setting['workSpace'];
			$this->query['t3ver_label']=mysql_real_escape_string($this->pi_getLL('info_t3ver_label'));
			$this->query['t3_origuid']=$uid_news;
			$GLOBALS['TYPO3_DB']->exec_INSERTquery(
				'tt_news',
				$this->query    			
			);
			$v_uid_news=$GLOBALS['TYPO3_DB']->sql_insert_id();
			for($i=0; $i<$this->query['category']; $i++)
			{
				$insertArray['uid_local'] = $v_uid_news;
				$insertArray['uid_foreign']	= $this->setting['add_category'][$i];
				$insertArray['sorting'] = $nr;
				
				$GLOBALS['TYPO3_DB']->exec_INSERTquery(
					'tt_news_cat_mm',
					$insertArray   			
				);
				$nr++;
			}
		}
		/*
		if($this->setting['for_fe_login']==1 && $what_to_display=='ADD')
		{
			$query=array(
			'tstamp'=>time(),
			'crdate'=>time(),
			'deleted'=>0,
			'hidden'=>0,
			'user'=>$GLOBALS["TSFE"]->fe_user->user['uid'],
			'news'=>$uid_news
			);
			
			if($this->setting['news_pid']!='') $query['pid']=$this->setting['news_pid'];
			else $query['pid']=intval($this->conf['newsPid']);
			
				$GLOBALS['TYPO3_DB']->exec_INSERTquery(
					'tx_mtfenews_usernews_related',
					$query   			
				);
		}
		*/
		
		if($this->setting['redirect_pages']!=0) 
		{
			if($this->setting['ttnews_parameter']==0)
			{
				$array_param = array(
				'useCacheHash' =>1,
				'parameter' => $this->setting['redirect_pages'].' _self',
				'returnLast'=>'url'
				);
			}
			else
			{
				$backto=$edit='';
				if($this->setting['ttnews_edit']==1) $edit='&'.$this->prefixId.'[edit]='.$uid_news;
				if($this->setting['tt_news_returnUrl']!=0) $backto='&tx_ttnews[backPid]='.$this->setting['tt_news_returnUrl'];

				$array_param = array(
				'useCacheHash' =>1,
				'parameter' => $this->setting['redirect_pages'].' _self',
				'additionalParams' => '&tx_ttnews[tt_news]='.$uid_news.$backto.$edit,
				'returnLast'=>'url'
				);
			}
			header('Location: '.$this->cObj->typolink('',$array_param));
			exit;
		}
		else 
		{
			$this->templateCode =  $this->cObj->fileResource($this->conf['templateFile']);	
			$template['insert'] = $this->cObj->getSubpart($this->templateCode,'###INSERT###');
			$markerArray['###INFO###']=$this->pi_getLL('insert_info');
			$return=$this->cObj->substituteMarkerArrayCached($template['insert'],$markerArray);
		}
		return $return;
	}

	function form($show,$request,$all,$what_to_display)
	{	
		$this->templateCode = $this->cObj->fileResource($this->conf['templateFile']);
		$template['template'] = $this->cObj->getSubpart($this->templateCode,'###TEMPLATE###');

		$news_error=0;
		$all_marker=array_values($all);
		$show_marker=array_keys($show);

		if($what_to_display=='EDIT') 
		{
			list($news_uid,$news_error,$all_value) = $this->edit_value($show);
			$this->news_uid=$news_uid;
		}

		if($news_error==0)
		{		
			$template['next_image'] = $this->cObj->getSubpart($this->templateCode,'###NEXT_IMAGE###');
			$content_next_image=$subpartArray['###NEXT_IMAGE###']='';		
			$markerArray['###NAME_SUBMIT###']=$this->prefixId.'[submit_news]';
			$markerArray['###VALUE_SUBMIT###']=$this->pi_getLL('submit');
			for($i=0; $i<count($all_marker); $i++)
			{
				$marker='###'.strtoupper($all_marker[$i]).'###';
				$subpartArray[$marker]='';
			}
			for($i=0; $i<count($show_marker); $i++)
			{
				$image_next='';
				$marker=$show_marker[$i];

				if(stristr($marker,'image_next'))
				{
					list($image_next)=explode('image_next',$marker);
					$image_next=$image_next.'image_next';
					$next_nr=explode('_',$marker);
					$next_nr=$next_nr[count($next_nr)-1];
				}
				if(in_array($image_next,$this->all_next_image))
				{
					if($show[$marker]==1) $set_value=$all_value[$marker];
					$subpartArray['###NEXT_IMAGE###'][$next_nr][$image_next]=
					$this->get_marker($marker,$request[$marker],$template['template'],$image_next,$what_to_display,$set_value,$news_uid,$next_nr);
				} 
				else 
				{
					if($show[$marker]==1) $set_value=$all_value[$this->db_all[$marker]];
					if($show[$marker]==1) 
					$subpartArray['###'.strtoupper($marker).'###']=$this->get_marker($marker,$request[$marker],$template['template'],$image_next,$what_to_display,$set_value,$news_uid);
				}
			}

			if($subpartArray['###NEXT_IMAGE###']!='') 
			{
				for($i=0; $i<count($subpartArray['###NEXT_IMAGE###']); $i++)
				{
					for($z=0; $z<count($this->all_next_image); $z++)
					{
						$image_next=$this->all_next_image[$z];
						$subpartArray['###'.strtoupper($image_next).'###'] = $subpartArray['###NEXT_IMAGE###'][$i][$image_next];
						
					}
					$content_next_image.=$this->cObj->substituteMarkerArrayCached($template['next_image'],$markerArray,$subpartArray);
				}
			}
	
			$subpartArray['###NEXT_IMAGE###']=$content_next_image;
			$markerArray['###ADDITIONALJS_POST###'] = implode(chr(10), $this->additionalJS_post);
			$markerArray['###ADDITIONALJS_SUBMIT###']= implode(';', $this->additionalJS_submit);
			$markerArray['###FORM_NAME###']='fe_'.$this->prefixId;
		}

		return $this->cObj->substituteMarkerArrayCached($template['template'], $markerArray, $subpartArray);
	}
	function get_marker($show,$request,$szablon,$image_next,$what_to_display,$set_value,$news_uid,$next_nr='')
	{
		$marker=strtoupper($show);
		$markerArray['###INFO###']=$markerArray['###ERROR_CLASS###']=$markerArray['###ERROR_MSG###']='';
		$show_config=$this->conf['config.'][$show];
		$markerArray['###INFO###']=$this->pi_getLL('info_'.$show);
		if($request==1) $markerArray['###REQUIRED###']=$this->conf['info.']['required']==''?$this->pi_getLL('required'):$this->conf['info.']['required'];
		else $markerArray['###REQUIRED###']='';

		if($image_next=='') $template = $this->cObj->getSubpart($szablon,'###'.$marker.'###');
		else 
		{
			$template = $this->cObj->getSubpart($szablon,'###'.strtoupper($image_next).'###');
			$show_config=$this->conf['config.'][$image_next];
			$markerArray['###INFO###']=$this->pi_getLL('info_'.$image_next);
		}

		if(isset($this->piVars['submit_news']) || $what_to_display=='EDIT') 
		{
			$markerArray['###ERROR_MSG###']=$this->get_error($show,$request,$image_next,$what_to_display,$set_value,$next_nr);
			if($markerArray['###ERROR_MSG###']!='') $this->error=$markerArray['###ERROR_CLASS###']='error';
		}

		$markerArray['###NAME###']=$this->prefixId.'['.$show.']';
		$markerArray['###CONF###']=$this->prefixId.'['.$show.'_';
		if($what_to_display=='EDIT' && !isset($this->piVars['submit_news']))
		{
		switch($show_config)
			{
				case 'input':
					$markerArray['###VALUE###']=$set_value;
				break;
				case 'textarea_rte':
	
				$this->postvars = t3lib_div::_POST($this->prefixId);
				if(!$this->RTEObj)  $this->RTEObj = t3lib_div::makeInstance('tx_rtehtmlarea_pi2');
				if($this->RTEObj->isAvailable()) {
				$this->RTEcounter++;
				$this->table = $show;
				$this->field = $show;
				$this->formName = $show;
				$this->PA['itemFormElName'] = $this->prefixId.'['.$show.']';
				$this->PA['itemFormElValue'] = $set_value;
				$this->thePidValue = $GLOBALS['TSFE']->id;
				$RTEItem = $this->RTEObj->drawRTE($this, $show, $show, $row=array(), $this->PA, $this->specConf, $this->thisConfig, $this->RTEtypeVal, '', $this->thePidValue);
				$markerArray['###ADDITIONALJS_PRE###'] = $this->additionalJS_initial.'
				<script type="text/javascript">'. implode(chr(10), $this->additionalJS_pre).'
				</script>';
				$markerArray['###ADDITIONALJS_POST###'] = '
				<script type="text/javascript">'. implode(chr(10), $this->additionalJS_post).'
				</script>';
				$markerArray['###ADDITIONALJS_SUBMIT###'] = implode(';', $this->additionalJS_submit);
				$markerArray['###TEXTAREA_RTE###'] = $RTEItem;
	
				$saveData = $this->postvars;
				$saveData[$show] = stripslashes($saveData[$show]);
				$saveData[$show] = $this->RTEObj->transformContent('db',$saveData[$show], 'tt_news', $show, $saveData, $this->specConf, $this->thisConfig, '', $this->thePidValue);
				$saveData[$show] = str_replace("\r\n"," ",$saveData[$show]);
				if($this->error=='') $this->query[$this->db_all[$show]]= preg_replace("/<\/?" . font . "(.|\s)*?>/","",$saveData[$show]);
				}
				break;
				case 'textarea':
					$markerArray['###VALUE###']=$set_value;
				break;
				case 'email':
					$markerArray['###VALUE###']=$set_value;
				break;
				case 'category':	
					$subpartArray['###CONTENT###']=$this->get_category($this->edit_category($news_uid),$template);
				break;
				case 'image':
					$markerArray['###VALUE###']=$this->upload_image($show,$markerArray['###ERROR_CLASS###'],$image_next,$set_value,$what_to_display);
				break;
				case 'captch':
					$subpartArray['###CAPTCH_INSERT###']=$this->captch($show,$template);
				break;
				default:
					$markerArray['###ERROR_MSG###']=$this->set_error($this->pi_getLL('wrong_config'));
					 $this->error=$markerArray['###ERROR_CLASS###']=' error';
				break;
			}
		}
		else
		{
			switch($show_config)
			{
				case 'input':
					$markerArray['###VALUE###']=$this->piVars[$show];
					if(stristr($show,'next'))
					{
						list($next_show)=explode('_next',$show);
						$next_show=$next_show.'_next';
						$markerArray['###MAX_LEN###']=$this->conf['config.'][$next_show.'.']['maxLen'];
						$markerArray['###MIN_LEN###']=$this->conf['config.'][$next_show.'.']['minLen'];
					}
					else
					{
						$markerArray['###MAX_LEN###']=$this->conf['config.'][$show.'.']['maxLen'];
						$markerArray['###MIN_LEN###']=$this->conf['config.'][$show.'.']['minLen'];
					}
				break;
				case 'textarea_rte':
					$markerArray['###MAX_LEN###']=$this->conf['config.'][$show.'.']['maxLen'];
					$markerArray['###MIN_LEN###']=$this->conf['config.'][$show.'.']['minLen'];
				$this->postvars = t3lib_div::_POST($this->prefixId);
				if(!$this->RTEObj)  $this->RTEObj = t3lib_div::makeInstance('tx_rtehtmlarea_pi2');
				if($this->RTEObj->isAvailable()) {
				$this->RTEcounter++;
				$this->table = $show;
				$this->field = $show;
				$this->formName = $show;
				$this->PA['itemFormElName'] = $this->prefixId.'['.$show.']';
				$this->PA['itemFormElValue'] = $this->postvars[$show];
				$this->thePidValue = $GLOBALS['TSFE']->id;
				$RTEItem = $this->RTEObj->drawRTE($this, $show, $show, $row=array(), $this->PA, $this->specConf, $this->thisConfig, $this->RTEtypeVal, '', $this->thePidValue);
				$markerArray['###ADDITIONALJS_PRE###'] = $this->additionalJS_initial.'
				<script type="text/javascript">'. implode(chr(10), $this->additionalJS_pre).'
				</script>';
				$markerArray['###ADDITIONALJS_POST###'] = '
				<script type="text/javascript">'. implode(chr(10), $this->additionalJS_post).'
				</script>';
				$markerArray['###ADDITIONALJS_SUBMIT###'] = implode(';', $this->additionalJS_submit);
				$markerArray['###TEXTAREA_RTE###'] = $RTEItem;
	
				$saveData = $this->postvars;
				$saveData[$show] = stripslashes($saveData[$show]);
				$saveData[$show] = $this->RTEObj->transformContent('db',$saveData[$show], 'tt_news', $show, $saveData, $this->specConf, $this->thisConfig, '', $this->thePidValue);
				$saveData[$show] = str_replace("\r\n"," ",$saveData[$show]);
				if($this->error=='') $this->query[$this->db_all[$show]]= preg_replace("/<\/?" . font . "(.|\s)*?>/","",$saveData[$show]);
				}
				break;
				case 'textarea':
					$markerArray['###MAX_LEN###']=$this->conf['config.'][$show.'.']['maxLen'];
					$markerArray['###MIN_LEN###']=$this->conf['config.'][$show.'.']['minLen'];
					$markerArray['###VALUE###']=$this->piVars[$show];
				break;
				case 'email':
					$markerArray['###MAX_LEN###']=$this->conf['config.'][$show.'.']['maxLen'];
					$markerArray['###MIN_LEN###']=$this->conf['config.'][$show.'.']['minLen'];
					$markerArray['###VALUE###']=$this->piVars[$show];
				break;
				case 'category':	
					$this->edit_category($news_uid);
					$subpartArray['###CONTENT###']=$this->get_category($this->piVars[$show],$template);
				break;
				case 'image':
					$markerArray['###VALUE###']=$this->upload_image($show,$markerArray['###ERROR_CLASS###'],$image_next);
				break;
				case 'captch':
					$subpartArray['###CAPTCH_INSERT###']=$this->captch($show,$template);
				break;
				default:
					$markerArray['###ERROR_MSG###']=$this->set_error($this->pi_getLL('wrong_config'));
					 $this->error=$markerArray['###ERROR_CLASS###']=' error';
				break;
			}
		}

		return $this->cObj->substituteMarkerArrayCached($template,$markerArray,$subpartArray);
	}
	function edit_value($show)
	{
		$return='';
		$error=1;
		$uid=intval($this->piVars['edit']);
		$user=intval($GLOBALS["TSFE"]->fe_user->user['uid']);
		
		$where = 'deleted=0 AND hidden=0 AND uid='.$uid.' AND tx_mtfenews_user='.$user;
		$res =  $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid','tt_news',$where,'','',1);
		while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))
		{
			$error=0;
			
		}
		if($error==0)
		{
			$add_field[]='uid';
			$marker=array_keys($show);
			$value=array_values($show);
			for($i=0; $i<count($show); $i++)
			{
				if($value[$i]==1 && $this->db_all[$marker[$i]]!='') $add_field[]=$this->db_all[$marker[$i]];
			}
			
			$where = 'deleted=0 AND hidden=0 AND uid='.$uid.'';
			$res =  $GLOBALS['TYPO3_DB']->exec_SELECTquery(implode(',',$add_field),'tt_news',$where,'uid','uid','1');
			while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))
			{
				if(stristr($row['image'],','))
				{
					$next_image=explode(',',$row['image']);
					$row['image']=$next_image[0];
					for($i=1; $i<count($next_image); $i++)
					{
						$row['image_next_'.($i-1)]=$next_image[$i];
					}
				}
				if(stristr($row['imagecaption'],"\n"))
				{
					$next_image=explode("\n",$row['imagecaption']);
					$row['imagecaption']=$next_image[0];
					for($i=1; $i<count($next_image); $i++)
					{
						$row['desc_image_next_'.($i-1)]=$next_image[$i];
					}
				}
				if(stristr($row['imagealttext'],"\n"))
				{
					$next_image=explode("\n",$row['imagealttext']);
					$row['imagealttext']=$next_image[0];
					for($i=1; $i<count($next_image); $i++)
					{
						$row['alt_image_next_'.($i-1)]=$next_image[$i];
					}
				}
				if(stristr($row['imagetitletext'],"\n"))
				{
					$next_image=explode("\n",$row['imagetitletext']);
					$row['imagetitletext']=$next_image[0];
					for($i=1; $i<count($next_image); $i++)
					{
						$row['title_image_next_'.($i-1)]=$next_image[$i];
					}
				}
				$return=$row;		
			}
		}
		return array($uid,$error,$return);
	}
	function edit_category($news_uid)
	{
		$category=array();

		$where = 'uid_local='.$news_uid;
		$res =  $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid_foreign','tt_news_cat_mm',$where);
		while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))
		{
			if(!in_array($row['uid_foreign'],$this->setting['without_category'])) $category[]=$row['uid_foreign'];
		}
		$this->category=$category;
		return $category;
	}
	function captch($show,$template)
	{
		$template = $this->cObj->getSubpart($template,'###CAPTCH_INSERT###');
		$markerArray['###UID###']=$show;
		$markerArray['###NAME###']=$this->prefixId.'['.$show.']';
		$return='';
		if (t3lib_extMgm::isLoaded('sr_freecap') ) 
		{
			require_once(t3lib_extMgm::extPath('sr_freecap').'pi2/class.tx_srfreecap_pi2.php');
			$this->freeCap = t3lib_div::makeInstance('tx_srfreecap_pi2');
			if (is_object($this->freeCap)) 
			{
				$markerArray = array_merge($markerArray, $this->freeCap->makeCaptcha());
				$return=$this->cObj->substituteMarkerArrayCached($template,$markerArray);
			}		
		}
		return $return;
	}
	function upload_image($show,$error,$image_next,$set_value,$what_to_display)
	{
		$file=$show;
		if($image_next!='') $show=$image_next;
		if($what_to_display=='EDIT' && $set_value!='' && !isset($this->piVars['submit_news']))
		{	
			if(!isset($this->piVars['delete_'.$file]))
			{
				$src=str_replace('/uploads','uploads',str_replace($_SERVER['DOCUMENT_ROOT'],'','uploads/pics/'.$set_value));
				$img = $this->conf['small_'.$show.'.'];
				$img['file']=$src;
				$this->templateCode =  $this->cObj->fileResource($this->conf['templateFile']);		
				$template['upload'] = $this->cObj->getSubpart($this->templateCode,'###UPLOAD###');
				$markerArray['###SRC###']=$src;
				$markerArray['###SMALL_SRC###']=$this->cObj->IMG_RESOURCE($img);
				$markerArray['###HIDDEN###']='
				<input name="'.$this->prefixId.'[hidden_'.$file.']" type="hidden" value="'.$set_value.'" />
				<input name="'.$this->prefixId.'[hidden_big_'.$file.']" type="hidden" value="'.$src.'" />
				<input name="'.$this->prefixId.'[hidden_small_'.$file.']" type="hidden" value="'.$this->cObj->IMG_RESOURCE($img).'" />
				';
				$markerArray['###DELETE###']=$this->prefixId.'[delete_'.$file.']';
				$markerArray['###VALUE_DELETE###']=$this->pi_getLL('value_delete');
				$return=$this->cObj->substituteMarkerArrayCached($template['upload'],$markerArray);
			}
			else
			{
				//unlink($this->piVars['hidden_big_'.$file]);
				$return='<input name="'.$file.'" type="file" size="'.$this->conf[$show.'.']['size'].'" />';
				//$this->query[$this->db_all[$show]]='';
			}

		}
		else
		{
			if(!isset($this->piVars['hidden_'.$file]))
			{
				if(isset($this->piVars['submit_news']) && $GLOBALS[HTTP_POST_FILES][$file]['error']==0 && $error=='' && 
				$GLOBALS[HTTP_POST_FILES][$file]['size']<$this->conf['config.'][$show.'.']['maxSize']  && $this->captch_error==0)
				{				
					$this->templateCode =  $this->cObj->fileResource($this->conf['templateFile']);		
					$template['upload'] = $this->cObj->getSubpart($this->templateCode,'###UPLOAD###');
					$template[$show] = $this->cObj->getSubpart($template['upload'],'###'.strtoupper($show).'###');
				
					$this->fileFunc = t3lib_div::makeInstance("t3lib_basicFileFunctions");
					$sauber = $this->fileFunc->cleanFileName($GLOBALS[HTTP_POST_FILES][$file][name]);
					$unique = $this->fileFunc->getUniqueName($sauber,PATH_site.$TYPO3_LOADED_EXT[$key]["siteRelPath"]."uploads/pics/");					
					move_uploaded_file($GLOBALS[HTTP_POST_FILES][$file][tmp_name],$unique);
					$src=str_replace('/uploads','uploads',str_replace($_SERVER['DOCUMENT_ROOT'],'',$unique));
					$new_name=str_replace('uploads/pics/','',$src);
					$img = $this->conf['small_'.$show.'.'];
					$img['file']=$src;
					$markerArray['###SRC###']=$src;
					$markerArray['###SMALL_SRC###']=$this->cObj->IMG_RESOURCE($img);
					$markerArray['###HIDDEN###']='
					<input name="'.$this->prefixId.'[hidden_'.$file.']" type="hidden" value="'.$new_name.'" />
					<input name="'.$this->prefixId.'[hidden_big_'.$file.']" type="hidden" value="'.$src.'" />
					<input name="'.$this->prefixId.'[hidden_small_'.$file.']" type="hidden" value="'.$markerArray['###SMALL_SRC###'].'" />
					';
					$markerArray['###DELETE###']=$this->prefixId.'[delete_'.$file.']';
					$markerArray['###VALUE_DELETE###']=$this->pi_getLL('value_delete');
					$return=$this->cObj->substituteMarkerArrayCached($template['upload'],$markerArray);
	
					if($this->error=='' && $this->query[$this->db_all[$show]]=='') $this->query[$this->db_all[$show]]=iconv('UTF-8', 'ASCII//TRANSLIT', mysql_real_escape_string(str_replace(' ','_',$new_name)));
					elseif($this->error=='') $this->query[$this->db_all[$show]]=$this->query[$this->db_all[$show]].",".iconv('UTF-8', 'ASCII//TRANSLIT', mysql_real_escape_string(str_replace(' ','_',$new_name)));
					
					
					
				}
				else
				{
					$return='<input name="'.$file.'" type="file" size="'.$this->conf[$show.'.']['size'].'" />';
					//$this->query[$this->db_all[$show]]='';
				}
			}
			else
			{
				if(!isset($this->piVars['delete_'.$file]))
				{
					$this->templateCode =  $this->cObj->fileResource($this->conf['templateFile']);		
					$template['upload'] = $this->cObj->getSubpart($this->templateCode,'###UPLOAD###');
					$template[$file] = $this->cObj->getSubpart($template['upload'],'###'.strtoupper($file).'###');
					$markerArray['###SRC###']=$this->piVars['hidden_big_'.$file];
					$markerArray['###SMALL_SRC###']=$this->piVars['hidden_small_'.$file];
					$markerArray['###HIDDEN###']='
					<input name="'.$this->prefixId.'[hidden_'.$file.']" type="hidden" value="'.$this->piVars['hidden_'.$file].'" />
					<input name="'.$this->prefixId.'[hidden_big_'.$file.']" type="hidden" value="'.$this->piVars['hidden_big_'.$file].'" />
					<input name="'.$this->prefixId.'[hidden_small_'.$file.']" type="hidden" value="'.$this->piVars['hidden_small_'.$file].'" />
					';
					$markerArray['###DELETE###']=$this->prefixId.'[delete_'.$file.']';
					$markerArray['###VALUE_DELETE###']=$this->pi_getLL('value_delete');
					$return=$this->cObj->substituteMarkerArrayCached($template['upload'],$markerArray);
				}
				else
				{
					unlink($this->piVars['hidden_big_'.$file]);
					$return='<input name="'.$file.'" type="file" size="'.$this->conf[$show.'.']['size'].'" />';
				}
			}
		}
		return $return;
	}
	function get_category($value,$szablon)
	{
	
		$template['category'] = $this->cObj->getSubpart($szablon,'###CONTENT###');
		$template['subcategory'] = $this->cObj->getSubpart($template['category'],'###SUB_CATEGORY###');
		$template['return'] = $this->cObj->getSubpart($template['subcategory'],'###RETURN###');
		$return='';
		
		if($this->setting['only_show_category'][0]!='')	
		{
			if(count($this->setting['only_show_category'])==1) 
			$where = 'deleted=0 AND hidden=0 AND pid='.intval($this->conf['categoryPid']).' AND uid='.intval($this->setting['only_show_category'][0]);
			else 
			$where = 'deleted=0 AND hidden=0 AND uid IN ('.implode(',',$this->setting['only_show_category']).') AND pid="'.intval($this->conf['categoryPid']).'"';
		}
		else $where = 'deleted=0 AND hidden=0 AND parent_category=0 AND pid="'.intval($this->conf['categoryPid']).'"';

		$res =  $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,title','tt_news_cat',$where);
		$subpartArray['###CONTENT###']='';
		while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))
		{	
			$subpartArray['###SUB_CATEGORY###']=$subpartArray['###RETURN###']='';
			if(!in_array($row['uid'],$this->setting['without_category']))
			{
				if(!in_array($row['uid'],$value)) $markerArray['###SELECTED###']='';
				else $markerArray['###SELECTED###']='selected="selected"';	
				
				if($template['subcategory']!='' && $template['return']!='') 
				{
					$subpartArray['###RETURN###']=$this->get_subcategory($row['uid'],$template['return'],$value);				
					if($subpartArray['###RETURN###']!='') $subpartArray['###SUB_CATEGORY###']=$this->cObj->substituteMarkerArrayCached($template['subcategory'],$markerArray,$subpartArray);
				}
				$markerArray['###VALUE###']=$row['uid'];
				$markerArray['###LABEL###']=$row['title'];
				
				$subpartArray['###CONTENT###'].=$this->cObj->substituteMarkerArrayCached($template['category'],$markerArray,$subpartArray);
			}
		}

		return $subpartArray['###CONTENT###'];
	}
	function get_subcategory($uid,$template,$value)
	{
		$return='';
		$where = 'deleted=0 AND hidden=0 AND parent_category='.$uid.' AND pid="'.intval($this->conf['categoryPid']).'"';
		$res =  $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,title','tt_news_cat',$where,'','sorting');
		while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))
		{	
			if(!in_array($row['uid'],$this->setting['without_category']))
			{
				if(in_array($row['uid'],$value) || isset($this->piVars['cat_checkbox']) && $this->piVars['cat'.$row['uid']]==$row['uid']) $markerArray['###SELECTED###']='selected="selected"';		
				else $markerArray['###SELECTED###']='';
				
				$markerArray['###VALUE###']=$row['uid'];
				$markerArray['###LABEL###']=$row['title'];
				$return.=$this->cObj->substituteMarkerArrayCached($template,$markerArray);
			}
		}
		return $return;
	}
	function set_error($content)
	{
		$return='';
		$stdWrap=$this->conf['error_wrap'];
		if($stdWrap!='' && stristr($stdWrap,'|')) $return = str_replace('|',$content,$stdWrap);
		else $return='<span class="set_error">'.$content.'</span>';
		return $return;
	}
	
	function get_error($show,$request,$next_show,$what_to_display,$set_value,$next_nr)
	{
		$true_show=$error='';
		if($next_show!='') list($show,$true_show)=array($next_show,$show);
		
		if($next_show!='') $file=$true_show;
		else $file=$show;
		
		if($what_to_display=='EDIT' && !isset($this->piVars['submit_news'])) $value=$set_value;
		else if($show!='category') $value=strip_tags($this->piVars[$file]);
		else $value=$this->piVars[$file];	
		switch($this->conf['config.'][$show])
		{
			case 'input':
				if($request==0 && $value!='' || $request==1 && $value!='') 
				{
					if(is_numeric($this->conf['config.'][$show.'.']['maxLen'])) if(strlen($value)>$this->conf['config.'][$show.'.']['maxLen']) $error=$this->pi_getLL('error_maxLen');
					if(is_numeric($this->conf['config.'][$show.'.']['minLen'])) if(strlen($value)<$this->conf['config.'][$show.'.']['minLen']) $error=$this->pi_getLL('error_minLen');	
				}	
	
				if($request==1 && $value=='') $error=$this->pi_getLL('error_empty_value');
				if($this->error=='' && $this->query[$this->db_all[$show]]=='') 
				{
					if(in_array($next_show,$this->all_next_image)) 
					{
						for($i=0; $i==$next_nr; $i++) $separation.="\n";
						$this->query[$this->db_all[$show]]=$separation.mysql_real_escape_string($value);
					}
					else $this->query[$this->db_all[$show]]=mysql_real_escape_string($value);
				}
				else if($this->error=='') $this->query[$this->db_all[$show]]=$this->query[$this->db_all[$show]]."\n".mysql_real_escape_string($value);
				else if(in_array($show,$this->all_no_empty)) $this->query[$this->db_all[$show]]="\n";
				
				
								
			break;
			case 'textarea':
				if($request==0 && $value!='' || $request==1 && $value!='') 
				{
					if(is_numeric($this->conf['config.'][$show.'.']['maxLen'])) if(strlen($value)>$this->conf['config.'][$show.'.']['maxLen']) $error=$this->pi_getLL('error_maxLen');
					if(is_numeric($this->conf['config.'][$show.'.']['minLen'])) if(strlen($value)<$this->conf['config.'][$show.'.']['minLen']) $error=$this->pi_getLL('error_minLen');	
				}			
				if($request==1 && $value=='') $error=$this->pi_getLL('error_empty_value');
				if($this->error=='' && $this->query[$this->db_all[$show]]=='') $this->query[$this->db_all[$show]]=mysql_real_escape_string($value);
				elseif($this->error=='') $this->query[$this->db_all[$show]]=$this->query[$this->db_all[$show]]."\n".mysql_real_escape_string($value);
			break;
			case 'textarea_rte':
				if($request==0 && $value!='' || $request==1 && $value!='') 
				{
					if(is_numeric($this->conf['config.'][$show.'.']['maxLen'])) if(strlen($value)>$this->conf['config.'][$show.'.']['maxLen']) $error=$this->pi_getLL('error_maxLen');
					if(is_numeric($this->conf['config.'][$show.'.']['minLen'])) if(strlen($value)<$this->conf['config.'][$show.'.']['minLen']) $error=$this->pi_getLL('error_minLen');	
				}			
				if($request==1 && $value=='') $error=$this->pi_getLL('error_empty_value');							
			break;
			case 'email':
				if($request==0 && $value!='' || $request==1 && $value!='') 
				{
					if(is_numeric($this->conf['config.'][$show.'.']['maxLen'])) if(strlen($value)>$this->conf['config.'][$show.'.']['maxLen']) $error=$this->pi_getLL('error_maxLen');
					if(is_numeric($this->conf['config.'][$show.'.']['minLen'])) if(strlen($value)<$this->conf['config.'][$show.'.']['minLen']) $error=$this->pi_getLL('error_minLen');	
				}	
				if($request==0 && $value!='' || $request==1) 
				if(!preg_match('/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is', $value)) $error=$this->pi_getLL('error_email_valid');
				if($request==1 && $value=='') $error=$this->pi_getLL('error_empty_value');
				if($this->error=='') $this->query[$this->db_all[$show]]=mysql_real_escape_string($value);
			break;
			case 'category':
				if($value!='' && !is_array($value)) $value=array($value);
				if($request==1 && $value=='') $error=$this->pi_getLL('error_empty_value');
				if($this->error=='' && $value!='') $this->query[$this->db_all[$show]]=$value;

			break;
			case 'image':

				setlocale(LC_CTYPE, 'pl_PL.UTF-8');
				if(!isset($this->piVars['hidden_'.$file]))
				{
					if($what_to_display=='EDIT' && isset($this->piVars['submit_news']) || $what_to_display=='ADD')
					{
						if($request==1 && $GLOBALS[HTTP_POST_FILES][$file]['error']!=0)  $error=$this->pi_getLL('error_fileUpload');
											
						if(is_numeric($this->conf['config.'][$file.'.']['maxSize'])  && $GLOBALS[HTTP_POST_FILES][$show]['error']==0) 
						if($GLOBALS[HTTP_POST_FILES][$file]['size']>$this->conf['config.'][$show.'.']['maxSize'])  $error=$this->pi_getLL('error_maxSize');
						
						if(is_numeric($this->conf['config.'][$show.'.']['minSize']) && $GLOBALS[HTTP_POST_FILES][$file]['error']==0) 
						if($GLOBALS[HTTP_POST_FILES][$file]['size']<$this->conf['config.'][$show.'.']['minSize'])  $error=$this->pi_getLL('error_minSize');
						if(stristr($this->conf['config.'][$show.'.']['type'],',')) $image_type=explode(',',$this->conf['config.'][$show.'.']['type']);
						else $image_type=array($this->conf['config.'][$show.'.']['type']);

						for($i=0; $i<count($image_type); $i++)
						{
							if($image_type[$i]=='jpg') $image_type[$i]='jpeg';
							$image_type[$i]='image/'.$image_type[$i];
						}

						if($GLOBALS[HTTP_POST_FILES][$file]['error']==0 && !in_array($GLOBALS[HTTP_POST_FILES][$file]['type'],$image_type))
						$error=$this->pi_getLL('error_fileType');
					}
				}
				elseif($this->error=='' && $this->query[$this->db_all[$show]]=='') $this->query[$this->db_all[$show]]=iconv('UTF-8', 'ASCII//TRANSLIT', mysql_real_escape_string(str_replace(' ','_',$this->piVars['hidden_'.$file])));
				elseif($this->error=='') $this->query[$this->db_all[$show]]=$this->query[$this->db_all[$show]].",".iconv('UTF-8', 'ASCII//TRANSLIT', mysql_real_escape_string(str_replace(' ','_',$this->piVars['hidden_'.$file])));
			break;
			case 'captch':
			
				if (t3lib_extMgm::isLoaded('sr_freecap') ) 
				{
						require_once(t3lib_extMgm::extPath('sr_freecap').'pi2/class.tx_srfreecap_pi2.php');
						$this->freeCap = t3lib_div::makeInstance('tx_srfreecap_pi2');
						if (is_object($this->freeCap)) 
						{
							if (!$this->freeCap->checkWord($value)) 
							{
								$this->captch_error=1;
								$error=$this->pi_getLL('error_captch');
							}
						}
				}else $error=$this->pi_getLL('wrong_config');
				
			break;
			default:
				$error=$this->pi_getLL('wrong_config');
			break;			
		}
		$this->error=$this->error.$error;
		if($error!='') $error=$this->set_error($error);
		return $error;
	}
}



if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/mt_fenews/pi1/class.tx_mtfenews_pi1.php'])	{
	include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/mt_fenews/pi1/class.tx_mtfenews_pi1.php']);
}

?>